home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / source_code / dhtmlunl / dhtml.exe / CD Content / Chap15 / dun15_4.txt < prev    next >
Encoding:
Text File  |  1997-12-18  |  2.3 KB  |  76 lines

  1. <IMG NAME=arrow SRC="arrow.gif" ALIGN=left>
  2.  
  3. <DIV ID=banner STYLE="position: absolute; left: 72; top: 15;">
  4.   <FONT FACE="Arial, Helvetica" SIZE=+2>
  5.       Exposing Page Elements Cross-Browser
  6.   </FONT>
  7. </DIV>
  8.  
  9.  
  10. <SCRIPT>
  11. // reflectElements:
  12. //
  13. //   Reflects elements from the document.all collection up one
  14. //   level to underneath the document object.
  15. //
  16. function reflectElements()
  17. {
  18.   for (var i=0; i<document.all.length; i++)
  19.   {
  20.     // If an element has an id and does not already exist
  21.     // under the document object, reflect the element object
  22.     // underneath the document object.
  23.  
  24.     if (document.all[i].id != "" &&
  25.         !eval("document." + document.all[i].id))
  26.     {
  27.        eval("document." + document.all[i].id +
  28.             " = document.all[" + i + "];");
  29.     }
  30.   }
  31. }
  32.  
  33. // Detect if browser is IE4 and if so, reflect page elements up
  34. // to document object.
  35. //
  36. if (navigator.appName.indexOf("Internet Explorer") != -1 &&
  37.     navigator.appVersion.charAt(0) == '4')
  38.       reflectElements();
  39. </SCRIPT>
  40.  
  41.  
  42. <BR><BR>
  43. <P>The <TT>DIV</TT> element is normally reflected as
  44. <TT>document.banner</TT> in Communicator 4.0 and
  45. <TT>document.all['banner']</TT> in IE4.  Using this script to
  46. manually reflect all named page elements beneath the document
  47. object allows both browsers to access the <TT>DIV</TT> element using
  48. <TT>document.banner</TT>.</P>
  49.  
  50. <P>The attributes of the <TT>DIV</TT> element that are reflected in both
  51. browsers include:</P>
  52.  
  53. <BLOCKQUOTE>
  54. <SCRIPT>
  55.   document.writeln("<B>id:</B> " + document.banner.id + "<BR>");
  56. </SCRIPT>
  57. </BLOCKQUOTE>
  58.  
  59. <P>The <TT>IMG</TT> element is normally reflected as
  60. <TT>document.arrow</TT> and <TT>document.images['arrow']</TT> in both
  61. Communicator 4.0 and IE4.</P>
  62.  
  63. <P>The attributes of the <TT>IMG</TT> element that are reflected in both
  64. browsers include:</P>
  65.  
  66. <BLOCKQUOTE>
  67. <SCRIPT>
  68.    document.writeln("<B>name:</B> " + document.arrow.name + "<BR>");
  69.    document.writeln("<B>src:</B> " + document.arrow.src + "<BR>");
  70.    document.writeln("<B>width:</B> " + document.images['arrow'].width +
  71.                     "<BR>");
  72.    document.writeln("<B>height:</B> " + document.images['arrow'].height +
  73.                     "<BR>");
  74. </SCRIPT>
  75. </BLOCKQUOTE>
  76.